package List.foreach;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

public class Test {
    public static void main(String[] args) {
        Collection ct = new ArrayList<>();
        ct.add("Java从入门到精通");
        ct.add("C语言从入门到精通");
        ct.add("C#从入门到精通");
        System.out.println(calNum(ct,e->((String)e).contains("C")));//
        System.out.println(calNum(ct,e->((String)e).contains("Java")));
        System.out.println(calNum(ct,e->((String)e).length()>8));


    }
    public static int calNum(Collection ct, Predicate pc){
        int number=0;
        for(Object obj:ct){
            if(pc.test(obj)){
                number++;
            }
        }
        return number;
    }
}
